package com.shiyingzi.dictionary.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.shiyingzi.common.PageableData;
import com.shiyingzi.common.ResponseData;
import com.shiyingzi.dictionary.model.Dictionary;
import com.shiyingzi.dictionary.service.IDictionaryService;


@RestController
@RequestMapping(value = "Dictionary")
public class DictionaryController {

	@Resource(name = IDictionaryService.BEAN_ID)
	private IDictionaryService dicService;
	
	@RequestMapping(value = "/query", method = { RequestMethod.GET, RequestMethod.POST })
	public PageableData<Dictionary> doQuery(int page, int limit, String dicName){
		return dicService.doQuery(page, limit, dicName);
	}
	
	@RequestMapping(value = "/doAddDic", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doAddDic(Dictionary dic){
		Dictionary addDictionary = dicService.addDictionary(dic);
		return new ResponseData(true, "", addDictionary);
	}
	
	@RequestMapping(value = "/doUpdateDic", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doUpdateDic(Dictionary dic){
		Dictionary modifyDictionary = dicService.modifyDictionary(dic);
		return new ResponseData(true, "", modifyDictionary);
	}
	
	@RequestMapping(value = "/doDeleteDic", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData doDeleteDic(Integer id){
		Dictionary delDictionary = dicService.delDictionary(dicService.getDictionaryById(id));
		return new ResponseData(true, "", delDictionary);
	}
	
}
